<template>
  <view class="contentV margin-sm">
    <view class="flex">
        <view class="text-xxl flex-sub">
          订单信息
        </view>
        <view class="flex-sub text-right" @tap="gotoOrderList">
          <button class="cu-btn round line-red">核销</button>
        </view>
    </view>
    <view scroll-x class="bg-white nav text-center solid-bottom">
      <view class="cu-item" :class="0==TabCur?'text-green cur':''" @tap="tabSelect" data-id="0">
        我的订单
      </view>
      <view class="cu-item" :class="1==TabCur?'text-green cur':''" @tap="tabSelect" data-id="1">
        团队订单
      </view>
    </view>
    <view>
      <view class="cu-list menu" v-if="0==TabCur">
        <view class="cu-item" v-for="(item,idx) in list" :key="idx">
          <view class="content">
            <view class="text-grey"> {{item.poiName}} </view>
            <view class="text-gray text-sm flex">
              <view class="text-cut">
                {{item.productName}}
              </view>
            </view>
          </view>
          <view class="action">
            <view class="text-grey text-xs text-center">{{item.payTime}}</view>
            <view class="cu-tag round bg-grey sm">￥{{item.orderPrice}}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import {verificateOrderList} from '../../common/api/order'
export default {
name: "payOkOrderList",
  data(){
      return {
        TabCur:0,
        list:[]
      }
  },
  methods: {
    tabSelect(e) {
      this.TabCur = e.currentTarget.dataset.id;
    },
    async loadList() {
      // const id = store.userId?store.userId:0
      const id = 1
      await verificateOrderList(id).then(res => {
        if (res.code == 200) {
          res.data.forEach(item=>{
            let time = item.order.payTime
            if(time) {
              time = time * 1000
              let date = new Date(time)
              console.log('data1:',date,time)
              time = this.formatDateTime(date,'HH:mm')
            }
            item['payTime'] = time
            this.list.push(item)
          })
        }
      })
    },
    formatDateTime(date, format){
      console.log('data:',date)
      const o = {
        'M+': date.getMonth() + 1, // 月份
        'd+': date.getDate(), // 日
        'h+': date.getHours() % 12 === 0 ? 12 : date.getHours() % 12, // 小时
        'H+': date.getHours(), // 小时
        'm+': date.getMinutes(), // 分
        's+': date.getSeconds(), // 秒
        'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
        S: date.getMilliseconds(), // 毫秒
        a: date.getHours() < 12 ? '上午' : '下午', // 上午/下午
        A: date.getHours() < 12 ? 'AM' : 'PM', // AM/PM
      };
      if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      for (let k in o) {
        if (new RegExp('(' + k + ')').test(format)) {
          format = format.replace(
              RegExp.$1,
              RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
          );
        }
      }
      return format;
    },
    gotoOrderList() {
      uni.navigateTo({url: `/pages/home/orderList`})
    }
  },
  mounted() {
    this.loadList()
  }
}
</script>

<style lang="scss" scoped>
.contentV {

}

</style>